package cn.tedu.csms.employee.service.impl;

import cn.tedu.csms.employee.mapper.EmployeeMapper;
import cn.tedu.csms.employee.pojo.dto.EmployeeQuery;
import cn.tedu.csms.employee.pojo.dto.EmployeeSaveParam;
import cn.tedu.csms.employee.pojo.entity.Employee;
import cn.tedu.csms.employee.pojo.vo.EmployeeVO;
import cn.tedu.csms.employee.service.IEmployeeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class EmployeeService implements IEmployeeService {

    @Autowired
    EmployeeMapper employeeMapper;

    @Override
    public List<EmployeeVO> select(EmployeeQuery employeeQuery) {
        log.debug("查询员工业务:参数={}",employeeQuery);
        return employeeMapper.select(employeeQuery);

    }

    @Override
    public void save(EmployeeSaveParam employeeSaveParam) {
        log.debug("保存员工业务:参数={}",employeeSaveParam);
        Employee employee = new Employee();
        BeanUtils.copyProperties(employeeSaveParam,employee);
        if(employee.getId()==null){
            employee.setCreateTime(new Date());
            employeeMapper.insert(employee);
        }else{
            employee.setUpdateTime(new Date());
            employeeMapper.update(employee);
        }

    }

    @Override
    public void delete(Long id) {
        log.debug("删除员工业务:参数={}",id);
        employeeMapper.delete(id);
    }

}
